<p>
<a href="?type=dump">dump</a>|
<a href="?type=data">data</a>|
<a href="?type=error">sql_error</a>|
<a href="?type=query">sql_query</a>|
<a href="?action=clean">clean_up</a> 
</p>
<ul>
<?php
/******************************
 * $File: index.php
 * $Description: 开发日志首页
 * $Author: chenwei
 * $Time:2014-05-20
 * Copyright(c) 2013 by chenwei All rights reserved
******************************/
header('Content-Type:text/html;charset=utf-8');//网站编码

function debug_log_path(){
    return __DIR__.DIRECTORY_SEPARATOR;
}
//清空一个目录和子目录下的文件
function debug_deldir($dir,$skip_file='index.php') {
    $dh=opendir($dir);
    while ($file=readdir($dh)) {
        if($file!="." && $file!="..") {
            $fullpath=$dir."/".$file;
            if(!is_dir($fullpath)) {
                if($file!=$skip_file){
                    $p = pathinfo($fullpath);
                    if(in_array($p['extension'],['txt','log'])){
                        unlink($fullpath);
                    }
                }
            } else {
                debug_deldir($fullpath);
            }
        }
    }
    closedir($dh);
}

function debug_clean_log(){
    if(!is_dir(debug_log_path()))return false;
    if(!is_writeable(debug_log_path()))@chmod(debug_log_path(),0777);
    debug_deldir(debug_log_path());
}

function debug_list_log($subdir=''){
    $logdir=debug_log_path();
    if(!is_dir($logdir))return false;
    if(!is_writeable($logdir))@chmod($logdir,0777);
    if($subdir == '')$subdir = 'dump';
    $dir = $logdir.$subdir.'/';
    $unexit = array();
    //获取目录下的文件
    if (is_dir($dir)) {
        if ($dh = opendir($dir)) {
            while (($file = readdir($dh)) !== false) {
                if($file!="."&&$file!=".."){
                    $unexit[]=$file;}
            }
            closedir($dh);
        }
    }
    return $unexit;
}

$action = !empty($_GET['action']) ? $_GET['action'] : '';
if($action == 'clean'){
    debug_clean_log();
}
$sub_dir = !empty($_GET['type']) ? $_GET['type'] : 'dump';
$files = debug_list_log($sub_dir);
foreach($files AS $file){
?>
<li><a href="<?php echo $sub_dir.'/'.$file;?>" target="_blank"><?php echo $file;?></a></li>
<?php
}
?>
</ul>